package com.aoxin.controller.html;

import com.aoxin.model.SlfPriceHistory;
import com.aoxin.service.inter.opm.PriceHistoryService;
import com.aoxin.util.AjaxRes;
import com.aoxin.util.Const;
import com.aoxin.util.enumerate.OperateType;
import com.aoxin.util.log.LogInfo;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@ResponseBody
@RequestMapping("/web/priceHistory")
public class PriceHistoryController {

	@Autowired
	private PriceHistoryService slfPriceHistoryService;

	/**
	 * 消费记录查询
	 * 
	 * @param slfPriceHistory
	 * @param ajaxRes
	 */
	@RequestMapping("/getBySlfPriceHistory")
	@LogInfo(content = "用户消费", operateType = OperateType.QUERY)
	public AjaxRes getBySlfPriceHistory(SlfPriceHistory slfPriceHistory, AjaxRes ajaxRes) {
		try {
			List<SlfPriceHistory> slfPriceHistorys = slfPriceHistoryService.getSlfPriceHistory(slfPriceHistory);
			ajaxRes.setSucceed(slfPriceHistorys, Const.DATA_SUCCEED);
		} catch (Exception e) {
			ajaxRes.setFailMsg(e.getMessage());
			e.printStackTrace();
		}
		return ajaxRes;
	}

	/**
	 * 消费记录添加
	 * 
	 * @param slfPriceHistory
	 * @param ajaxRes
	 */
	@RequestMapping("/insertSlfPriceHistory")
	@LogInfo(content = "用户消费", operateType = OperateType.INSERT)
	public AjaxRes insertSlfPriceHistory(SlfPriceHistory slfPriceHistory, AjaxRes ajaxRes) {
		try {
			slfPriceHistoryService.insertSlfPriceHistory(slfPriceHistory);
			ajaxRes.setSucceedMsg(Const.SAVE_SUCCEED);
		} catch (Exception e) {
			ajaxRes.setFailMsg(e.getMessage());
		}
		return ajaxRes;
	}

	@RequestMapping("/deletePriceHistory")
	@LogInfo(content = "用户消费", operateType = OperateType.DELETE)
	public AjaxRes deletePriceHistory(List<Integer> historyIds, AjaxRes ajaxRes) {
		try {
			slfPriceHistoryService.deletePriceHistory(historyIds);
			ajaxRes.setSucceedMsg(Const.DEL_SUCCEED);
		} catch (Exception e) {
			ajaxRes.setFailMsg(e.getMessage());
			e.printStackTrace();
		}
		return ajaxRes;
	}

	/**
	 * 消费记录修改
	 * 
	 * @param slfPriceHistory
	 * @param ajaxRes
	 */
	@RequestMapping("/updateBySlfPriceHistory")
	@LogInfo(content = "用户消费", operateType = OperateType.UPDATE)
	public AjaxRes updateBySlfPriceHistory(SlfPriceHistory slfPriceHistory, AjaxRes ajaxRes) {
		try {
			slfPriceHistoryService.updateSlfPriceHistory(slfPriceHistory);
			ajaxRes.setSucceedMsg(Const.UPDATE_SUCCEED);
		} catch (Exception e) {
			ajaxRes.setFailMsg(e.getMessage());
		}
		return ajaxRes;
	}

	/**
	 * 消费记录删除
	 * 
	 * @param historyId
	 * @param ajaxRes
	 */
	@RequestMapping("/deleteBySlfPriceHistory")
	@LogInfo(content = "用户消费", operateType = OperateType.DELETE)
	public AjaxRes deleteBySlfPriceHistory(Integer historyId, AjaxRes ajaxRes) {
		try {
			slfPriceHistoryService.deleteSlfPriceHistory(historyId);
			ajaxRes.setSucceedMsg(Const.DEL_SUCCEED);
		} catch (Exception e) {
			ajaxRes.setFailMsg(e.getMessage());
		}
		return ajaxRes;
	}
}
